/*
* Copyright (c) LSE
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in the
*       documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY LSE AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL LSE BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "multiboot.h"
#include "kstd.h"
#include "write.h"
#include "memory.h"
#include "idt.h"
#include "pic.h"
#include "timer.h"

void	k_main(unsigned long		magic,
	       multiboot_info_t*	info)
{
  (void) magic;
  (void) info;

  {
    unsigned int i = 0;
    unsigned int u = 0;
    char str[4];

    init_console();
    printf("Console\t\t    OK\n");
    printf("GDT\t\t\t");
    init_gdt();
    printf("OK\n");
    printf("IDT\t\t\t");
    __asm__ ("sti\n\t");
    init_idt();
    printf("OK\n");
    printf("Keyboard\t\t");
    init_pics ();
    printf("   OK\n");
    printf("Timer\t\t");
    init_timer();
    printf("OK\n");

    //str[0] = 3 / i;
    i = 0;
    /* while (1) */
    /*   { */
    /* 	printf("%d\n", gettick()); */
    /*   } */

    while (1)
      {
	//manage_time();
	// for (i = 0; i < 465456498; i++);
	//printf("%d\n", gettick());
	printf("%c", getkey ());
      }
    for (i = 0; i < 1500; i++)
      {
    	str[0] = '0' + (i / 100 % 10);
    	str[1] = '0' + (i / 10 % 10);
    	str[2] = '0' + (i % 10);
    	str[3] = '\n';
    	write (str, 4);
    	str[0] = 255;
    	str[1] = 3;
    	str[2] = i % 80;
    	write (str, 3);
    	str[0] = 255;
    	str[1] = 2;
    	str[2] = i % 255;
    	write (str, 3);
    	for (u = 0; u < 1000000; u++);
      }
    str[0] = '0' + (i / 100 % 10);
    str[1] = '0' + (i / 10 % 10);
    str[2] = '0' + (i % 10);
    write (str, 3);
    while (1)
      i = 0;
  }
  return;
}
